package com.edais.util;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;

import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.util.StringUtils;

import com.ctc.smscloud.xml.http.RespInfo;
import com.ctc.smscloud.xml.http.utils.XMLHttpClientUtil;

/***
 * (手机)大汉三通短信系统 工具
 *
 */
public class SanTongSmsUtil {
	private static final String DEFAULT_ENCODING = "utf-8";
	private static ResourceBundle bundle = null;
	private static final Logger logger = Logger.getLogger(SanTongSmsUtil.class);
	

	/**
	 * 获取短信模板
	 */
	public SanTongSmsUtil() {
		bundle = ResourceBundle.getBundle("sms");
	}

	public String tSmsContent(String key, Map<String, String> paraMap) {
		String m = bundle.getString(key);
		if (StringUtils.isEmpty(m)) {
			logger.error("sms.properties文件中无此键值对应,key=" + key);
			return "";
		}
		try {
			m = new String(m.getBytes("ISO-8859-1"), DEFAULT_ENCODING);
		} catch (UnsupportedEncodingException e) {
			logger.error("sms.properties转码发生错误,错误信息：" + e.getMessage());
			return "";
		}
		for (int i = 0; i < paraMap.size(); i++) {
			m = m.replace("{" + i + "}",
					(CharSequence) paraMap.get(String.valueOf(i)));
		}
		return m;
	}

	
	// 多个手机号码逗号分割
	public String listToString(List<String> mobileList){
		String mobileListParams = "";
		for (String mobile : mobileList) {
			mobileListParams = mobileListParams.concat(mobile.concat(","));
		}

		mobileListParams = mobileListParams.substring(0,
				mobileListParams.length() - 1);
		return mobileListParams;
	}

	public static void main(String args[]) {
		String randomCode = CommonUtil.getRandomCode();
		Map<String, String> smsMap = new HashMap<String, String>();
		smsMap.put("0", randomCode);
		SanTongSmsUtil smsUtil = new SanTongSmsUtil();
		System.out.println(smsUtil.tSmsContent("other_template", smsMap));

	}
}
